import { RequestModel } from '../../models/requestModel.js'
let requsetModel = new RequestModel()
Page({
  data: {
    selectItem:0,
    couponList:[{ title: '友阿优惠券', id: '0' }, { title: '联盟优惠券', id: '1' },{ title: '已失效优惠券', id: '2' }],
    pageList:[],
    selectItemCSS:0
  },
  onLoad: function (options) {
    this._getPageList(this.data.selectItem)
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  },
  onSwitch(e){
    console.log(e.currentTarget.dataset.id)
    this.setData({
      selectItem: e.currentTarget.dataset.id
    })
    this._getPageList(this.data.selectItem)
    wx.showLoading({
      title: '加载ing。。。',
    })
  },
  _getPageList(selectItem){
    console.log(selectItem)
    let reqData = { 'pageSize': 50, 'pageIndex': 1 }
    if (selectItem==0){
      reqData['isMerchants'] = '0';
      reqData['status'] = '0';
    }
    if (selectItem == 1){
      reqData['isMerchants'] = '1';
      reqData['status'] = '0';
    }
    if (selectItem == 2){
      reqData['status'] = '3';
    }
    requsetModel.requestPost({
      urlType: 'MARKETINGTK',
      url: 'coupon/v1/findUserCouponList',
      reqData: reqData,
      islogin: true
    }).then(res=>{
      // console.log(res.object.result)
      let tempList = res.object.result
      for (var i = 0; i < tempList.length; i++) {
        var tdic = tempList[i];
        var issueStartTime = tdic['issueStartTime'];
        tdic['issueStartTime'] = issueStartTime.substr(0, 10).replace(/-/g, '/');
        var validityDate = tdic['validityDate'];
        tdic['validityDate'] = validityDate.substr(0, 10).replace(/-/g, '/');
      }
      this.setData({
        // pageList: res.object.result
        pageList: tempList,
        selectItemCSS: selectItem
      })
      wx.hideLoading()
    })
  }
})